<extend name="./Public/templete/base.html"/>
<!-- 标题   -->
<block name="title">
  <title>编辑</title>
</block>
<!-- 添加该页面对应需要的css文件 -->
<block name="link">
  <link rel="shortcut icon" src="./favicon.ico" />
  <link rel="stylesheet" type="text/css" href="../../../../../Public/source/layui/css/layui.css">
</block>
<!-- 右下侧的主体内容 主要内容在此处写 -->
<block name="content">
    <div class="layui-body">
        <div style="padding: 15px;">
<!-- 我的代码 -->
   <!-- 一个简单的页面头部 -->
   <i class="layui-icon layui-icon-face-smile-b" style="font-size: 20px;"></i><label>&nbsp;修改会议内容</label>
   <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;"></fieldset>
   <form class="layui-form"> 
  <!-- 会议日期的选择 -->
     <div class="layui-inline" style="margin-bottom: 10px;">
       <label class="layui-form-label">会议日期：</label>
        <div class="layui-input-inline">
          <input class="layui-input" id="test11" placeholder="yyyy-mm-dd" type="text" autocomplete="off">
        </div>
     </div>
  <!-- 会议类型的选择 --> 
     <div class="layui-inline" style="display:block;">
       <label class="layui-form-label">会议类型：</label>
       <div class="layui-input-inline" style="padding-bottom: 10px;width: 186.4px;height: 38px;">
           <select lay-filter="aihao" id="sort">
               <option value="1">思政例会</option>
               <option value="2">教师指导</option>
               <option value="3" selected="">培训会议</option>
              </select>
       </div>
     </div>
  <!-- 主讲人的选择 -->
     <div class="layui-inline" style="padding-bottom: 10px;display:block;">
      <label class="layui-form-label">主讲人：</label>
         <div class="layui-input-inline">
          <input class="layui-input" type="text" id="host" autocomplete="off">         
         </div>
     </div>
  <!-- 参会人员的选择 -->
      <div class="layui-inline" style="padding-bottom: 10px;
      display:block;">
      <label class="layui-form-label">参会人员：</label>
         <textarea type="" name="" id="member" autocomplete="off" class="layui-textarea" id="join" style="width: 80%;"></textarea>      
     </div>
  <!-- 标题和内容 -->
     <div class="layui-form-item">
      <label class="layui-form-label">会议标题：</label>
        <div class="layui-input-block" style="width: 80%;">
           <input name="title" lay-verify="title" autocomplete="off" class="layui-input" type="text" id="title">
        </div>
         <label class="layui-form-label">会议内容：</label>
        <div class="layui-input-block" style="width: 80%;margin-top: 10px;">  
           <textarea  class="layui-textarea" id="content"></textarea>
        </div>
     </div>
   <!-- 文件上传 -->
   <label class="layui-form-label">相关文件：</label>
    <input type="text" id="startname" style="border: none;margin-top: 10px;">
    <input type="hidden" id="savename" style="border: none;">
   <div class="layui-upload">
      <button type="button" class="layui-btn layui-btn-normal" id="test8" style="margin-top: 15px;">选择文件</button>
      <button type="button" class="layui-btn" id="test9" style="margin-top: 25px; margin-bottom: 10px;">开始上传</button>
   </div>
    
    <!-- 提交和重置按钮键 -->
      <div class="layui-input-block" id="hide">
         <!-- 提交啦啦啦 -->
         <input type="button" class="layui-btn" id="Submit" value="立即提交">
         <!-- html自带的重置功能 -->
         <input type="reset" class="layui-btn layui-btn-primary">
      </div>
    </form>  
  <!-- 文件上传 -->    
<!-- 我的代码-->
        </div>
    </div>
</block>  
<!-- 引入或写js代码 -->
<block name="js">
  <script src="../../../../../Public/source/layui/layui.js"></script>
  <script type="text/javascript" src="../../../../../Public/source/jquery-3.2.1.js">
  </script>
  <script>
 // 日期选择
  layui.use('laydate', function(){
  var laydate = layui.laydate;
  laydate.render({
    elem: '#test11'
    ,format: 'yyyy-mm-dd'
   });
 });
//下拉框
layui.use(['form'], function(){
});
//从后台获取数据填充表单
$(function(){
$.ajax({
  async:true,
  type:'post',
  url:"__URL__/ShowDetail/id/{$data.id}",
  success:function(data)
  {
    console.log(data);
    $("#test11").val(data.date);
    $("#host").val(data.host);
    $("#member").val(data.member);
    $("#content").val(data.content);
    $("#title").val(data.title);
    $("#sort").find("option[value ="+data.sort+"]").attr("selected","selected");
     layui.form.render('select'); 
    $("#startname").val(data.filename);
    $("#savename").val(data.filesave)
  },
  error:function(data){
    alert('error');
  }
});  
})
//更新数据
$("#Submit").click( function(){
     var date1 = $("#test11").val();
     var host1 = $("#host").val();
     var member1 = $("#member").val();
     var content1 = $("#content").val();
     var title1 = $("#title").val();
     var sort1 = $("#sort option:selected").text();
     var startname1 = $("#startname").val();
     var savename1 = $("#savename").val();
     $.ajax({
       type:"POST",
       async:false,
       dataType:'json',
       url:"__URL__/Update/id/{$data.id}",//后台提供接口
       data:{
           date:date1,
           host:host1,
           member:member1,
           content:content1,
           title:title1,
           sort:sort1,
           filename:startname1,
           filesave:savename1
       }, 
       success:function(data)
       {
            console.log(data);
            layer.open({
               title:'提示',
               content: '提交成功',
               area: ['450px', '160px'],
               closeBtn: 2,
               time :2000,
           });
       },
       error:function(data)
       {
           layer.open({
               title:'提示',
               content: '请检查内容是否填写完整',
               btn: ['知道了'],
               area: ['500px', '180px'],
               closeBtn: 2,
           });
       }
     });
});
layui.use('element', function(){
      var element = layui.element;
    });
//文件上传
  layui.use('upload', function(){
  var $ = layui.jquery,
  upload = layui.upload;
  upload.render({
     elem: '#test8'
    ,type: 'file'
    ,url:"{:U('Conference/upload')}"//后台提供接口
    ,accept: 'file'
    ,auto: false
    ,bindAction: '#test9'
    ,done: function(res){    
      $('#startname').val(res[0]);
      $('#savename').val(res[1]);
       layer.open({
         title:'提示',
         content: '上传成功',
         btn: ['OK'],
         area: ['300px', '160px'],
         closeBtn: 2,
         time: 1500,
      });
    }
   ,error: function(){
      //请求异常回调
      layer.open({
         title:'提示',
         content: '上传失败',
         btn: ['知道了'],
         area: ['300px', '160px'],
         closeBtn: 2,
         time: 1500,
      });
    }
  });
});    
</script>
</block>